//两次点击返回
var first = null;
var index = {
	onopen : function(){
		var _opt = getToKen();
		_opt['cmd'] = 'red_send_log';
		_opt['from'] = 'public';
		ws.send(JSON.stringify(_opt));
	},
	onmessage : function(e){
		var data = eval("("+e.data+")");
		var fireData = {};
	    switch(data['type']){
	        // 服务端ping客户端
	        case 'ping':
	            ws.send('{"type":"pong"}');
	            break;
	        case 'pong':
	        	fireData = {
	        		type : 'online',
		        	online : data['online'],
		        };
	        	pushSubWebview(fireData);
	        	break;
	        // 登录 更新用户列表
	        case 'index':
	        	fireData = {
	        		type : 'init',
		        	online : data['online'],
		        };
	            break;
	    }
	},
	gamelist : function(){
	    var _opt = '{"type":"gamelist"}';
	    ws.send(_opt);
	},
	onchecklogin : function(){
		var _opt = getToKen();
		_opt['type'] = "checklogin";
		isDebug && console.log(JSON.stringify(_opt));
	    ws.send(JSON.stringify(_opt));
	},
}
mui.init({
	swipeBack: false,
});
mui.ready(function() {
	var username = getCookie("username");
	if(!username){
		username = "guest_" + generateMixed(8);
		setCookie("username",username);
	}
	window.addEventListener('onload',function(e){
		document.getElementById('loading').style.display = 'none';
	},false);
	clearCookie();
	//开始取数据保存到本地
	room_connect(index.onopen,index.onmessage,false);
});
